Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

317
Vistas
Doxygen and "self" keyword on PHP documentation

I'm tryin to document a my PHP library with doxygen, but I cannot configure it to let recognize the correct usage of member function of my class, using the keyword "self". For instance the following code:

Class myclass{
    public static function myfunc1(){
      return 10; }
    public static function myfunc2(){
      return self::myfunc1(); }
}

is not correctly documented. Doxygen maps the two funcions, but when it refer to the internal or external call to these function, it doesn't take in account the myfunc1 called by myfunc2.

My workaround at the moment is to changed the code as follows:

Class myclass{
    public static function myfunc1(){
      return 10; }
    public static function myfunc2(){
      return myclass::myfunc1(); }
}

In this case doxygen refers correctly to the usage of myfunc1 related to myfunc2. Of course I don't like very much this solution. How can I solve this issue? thank you very much

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Doxygen provides input filter option, which enables us to change the source code at the time of documentation creation. For e.g. It gives us ability to intercept the code and change the code self::myfunc1 to myclass::myfunc1 on fly, which Doxygen understands. It does not change the actual source code in any way.

I have created a filter based on code from Doxygen PHP Filters with some modifications, which can do the changes for you.

Please create a file /path/to/selfFilter.php and put the code inside it:

<?php
//Create file /path/to/selfFilter.php

$source = file_get_contents($argv[1]);
$tokens = token_get_all($source);
$classes = array();
foreach($tokens as $key => $token)
{
    if($token[0] == T_CLASS)
        $classes[] = $tokens[$key+2][1];
}
if(!empty($classes))
{
    list($source, $tail) = explode('class ' . $classes[0], $source, 2);
    $class_code = '';
    for($i = 1; $i < count($classes); $i++)
    {
        list($class_code, $tail) = explode('class ' . $classes[$i], $tail, 2);
        $class_code = preg_replace('#\bself::#', $classes[$i-1].'::', $class_code);
        $source .= 'class ' . $classes[$i-1] . $class_code;
    }
    $class_code = preg_replace('#\bself::#', $classes[count($classes)-1].'::', $tail);
    $source .= 'class ' . $classes[count($classes)-1] . $class_code;

}

echo $source;

Update the following options in your doxygen config file.

INPUT_FILTER           = "php /path/to/selfFilter.php"
FILTER_PATTERNS        = 
FILTER_SOURCE_FILES    = YES
FILTER_SOURCE_PATTERNS =

Please make sure that the /path/to/selfFilter.php is executable and php is available on the path, otherwise use the full php path

INPUT_FILTER           = /usr/bin/php /path/to/selfFilter.php

If you run the Doxygen now it should work. Please let me know if you have any issues.

Note: The keyword 'class' should be defined in lower case for the above filters to work.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda